﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace PTExpress.DataAccess
{
    public static class XeAccess
    {
        public static DataTable LayTatCaXe(string column)
        {
            return DataProvider.QueryResults(string.Format("select {0} from Xe", string.IsNullOrEmpty(column) ? "*" : column)).Tables[0];
        }

        //Tạo mới nhân viên
        static public DataTable CreateNewXe()
        {
            DataTable tb = DataProvider.QueryResults(@"SELECT * FROM v_Xe WHERE 1=0").Tables[0];
            DataRow row = tb.NewRow();
            row["so_hieu"] = "";
            row["ten_xe"] = "";
            row["hang_xe"] = "";
            row["loai_xe"] = 0;
            row["so_ghe"] = 4;
            row["tinh_trang"] = 0;
            tb.Rows.Add(row);
            return tb;
        }

        //Kiểm tra Xe tại
        static public bool KiemTraXeTonTai(string so_hieu)
        {
            double n = (int)DataProvider.ScalarExecute("SELECT COUNT(*) FROM Xe WHERE so_hieu = '" + so_hieu + "'");
            if (n > 0)
                return true;
            return false;
        }

        //Thêm phòng
        static public int ThemXe(DataTable tb)
        {
            string so_hieu = tb.Rows[0]["so_hieu"].ToString();
            if (LayTatCaXe("maphong").Select("maphong ='" + so_hieu + "'").Length <= 0)
                return DataProvider.Insert(tb, "dmPhong", "id");
            else
                return DataProvider.Update(tb, "dmPhong", "id,maphong");
        }

        //Xóa phòng
        static public int XoaXe(string ma)
        {
            DataTable tb = new DataTable();
            tb.Columns.Add("so_hieu");
            tb.Rows.Add(ma);
            return DataProvider.Detele(tb, "so_hieu");
        }
    }
}
